<template>
  <div class="app-container">
    <template>
      <div class="hidden-md-and-up">
        <el-alert title="如若不适应手机端操作，建议使用电脑操作" type="warning" />
      </div>
    </template>
    <div class="table-container">
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 260px;">
          <label>项目名称</label>
          <el-input v-model="search.projectName" size="medium" placeholder="输入关键字搜索" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>项目编号</label>
          <el-input v-model="search.projectId" size="medium" placeholder="输入关键字搜索" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>项目类别</label>
          <el-input v-model="search.projectCate" size="medium" placeholder="输入关键字搜索" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>项目来源单位</label>
          <el-input v-model="search.projectUnit" size="medium" placeholder="输入关键字搜索" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>项目负责人</label>
          <el-input v-model="search.headName" size="medium" placeholder="输入关键字搜索" style="width: 160px;" />
        </div>
      </div>
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 220px;">
          <label>项目状态</label>
          <el-select v-model="search.projectState" size="medium" placeholder="请选择" style="width: 160px;" @change="statusChange">
            <el-option label="全部" value="" />
            <el-option label="结题待院审核" value="结题待院审核" />
            <el-option label="结题待校审核" value="结题待校审核" />
            <el-option label="项目结题" value="项目结题" />
            <el-option label="项目结题退回" value="项目结题退回" />
          </el-select>
        </div>
        <div style="width: 600px; display: flex; align-items: center; gap: 8px; margin-left: 20px;">
          <label>项目开始时间</label>
          <div style="flex: 1">
            <el-date-picker
              v-model="search.startTimeStart"
              type="date"
              placeholder="起始时间"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 100%"
            />
          </div>
          <span style="flex-shrink: 0; margin: 0 4px">-</span>
          <div style="flex: 1">
            <el-date-picker
              v-model="search.startTimeEnd"
              type="date"
              placeholder="结束时间"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 100%"
            />
          </div>
        </div>
        <div style="width: 220px; margin-left: 20px;">
          <label>所属学院</label>
          <el-select
            v-model="search.deptName"
            :loading="deptLoading"
            size="medium"
            placeholder="请选择"
            filterable
            clearable
            style="width: 160px;"
            @focus="fetchDeptData"
          >
            <el-option label="全部" value="" />
            <el-option v-for="item in dept_options" :key="item.deptID" :label="item.deptName" :value="item.deptName" />
          </el-select>
        </div>
      </div>
      <el-table
        v-loading="paperListLoading"
        :data="paperList"
        element-loading-text="Loading"
        border
        fit
      >
        <el-table-column type="selection" align="center" width="55" />
        <!-- <el-table-column align="center" label="序号" width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column> -->
        <el-table-column align="center" label="项目名称" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.projectName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目编号" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.projectId }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目类别" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.projectCate }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目来源单位" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.projectUnit }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目负责人" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.headName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目成员" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.memberNames || '暂无' }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="合同经费（万元）" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.contractFunds || '0' }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="项目状态" min-width="100">
          <template slot-scope="scope">
            <el-tag :type="scope.row.projectState | statusFilter">{{ scope.row.projectState }}</el-tag>
            <el-tag v-if="scope.row.status === '被院级退回' || scope.row.status === '被校级退回'" type="warning">{{ scope.row.reason }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="230">
          <template slot-scope="scope">
            <el-popover
              :ref="`popoverpass-${scope.$index}`"
              placement="top"
              width="160"
            >
              <p>确认通过吗？该操作不可撤销</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope._self.$refs[`popoverpass-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="thesis_pass(scope.$index, scope.row)">确定</el-button>
              </div>
            </el-popover>
            <el-button
              size="mini"
              @click="open_infoview_dialog(scope.row)"
            >
              查看
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="thesis_back(scope.row)"
            >
              退回
            </el-button>
            <el-button
              v-popover="`popoverpass-${scope.$index}`"
              size="mini"
              type="success"
            >
              通过
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          background
          :current-page="p1_page"
          :page-sizes="[1,2,3,10, 20, 30, 40]"
          :page-size="p1_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="p1_total"
          @size-change="p1_sizechange"
          @current-change="p1_currentchange"
        />
        <!-- @size-change="handleSizeChange"
          @current-change="handleCurrentChange" -->
        <!-- 使用了size-change和current-change事件来处理页码大小和当前页变动时候触发的事件。 -->
      </div>
      <el-dialog title="查看信息" :visible.sync="infoview_dialog" width="75%">
        <el-collapse v-model="activeNames">
          <el-collapse-item name="1">
            <template slot="title">
              <div class="el-descriptions__title">项目信息</div>
            </template>
            <el-descriptions :column="2" size="medium" border :label-style="{width:'25%'}" :content-style="{width:'25%'}">
              <el-descriptions-item label="横向项目ID">
                {{ infoview1.tregistrationID }}
              </el-descriptions-item>
              <el-descriptions-item label="录入人">
                {{ infoview1.entered }}
              </el-descriptions-item>
              <el-descriptions-item label="录入日期">
                {{ infoview1.enteredDate }}
              </el-descriptions-item>
              <el-descriptions-item label="项目名称">
                {{ infoview1.projectName }}
              </el-descriptions-item>
              <el-descriptions-item label="项目编号">
                {{ infoview1.projectId }}
              </el-descriptions-item>
              <el-descriptions-item label="项目类别">
                {{ infoview1.projectCate }}
              </el-descriptions-item>
              <el-descriptions-item label="来源单位类型">
                {{ infoview1.sourceUnitType }}
              </el-descriptions-item>
              <el-descriptions-item v-if="infoview1.sourceUnitType === '国有企业' || infoview1.sourceUnitType === '民营企业'" label="来源企业/公司分类">
                {{ infoview1.sourceEnterpriseCategory }}
              </el-descriptions-item>
              <el-descriptions-item label="项目来源单位">
                {{ infoview1.projectUnit }}
              </el-descriptions-item>
              <el-descriptions-item label="来源单位/企业所在省、市">
                {{ infoview1.projectSourceUnit }}
              </el-descriptions-item>
              <el-descriptions-item label="项目负责人">
                {{ infoview1.headName }}
              </el-descriptions-item>
              <el-descriptions-item label="项目成员">
                {{ infoview1.projectMembersName }}
              </el-descriptions-item>
              <el-descriptions-item label="项目开始日期">
                {{ infoview1.startTime }}
              </el-descriptions-item>
              <el-descriptions-item label="项目结束日期">
                {{ infoview1.endTime }}
              </el-descriptions-item>
              <el-descriptions-item label="立项日期">
                {{ infoview1.approvalTime }}
              </el-descriptions-item>
              <el-descriptions-item label="立项年度">
                {{ infoview1.approvalYear }}
              </el-descriptions-item>
              <el-descriptions-item label="档案编号">
                {{ infoview1.archiveNum }}
              </el-descriptions-item>
              <el-descriptions-item label="财务项目号">
                {{ infoview1.archiveNum }}
              </el-descriptions-item>
              <el-descriptions-item label="到校经费(万元)">
                {{ infoview1.arrivingFunds }}
              </el-descriptions-item>
              <el-descriptions-item label="合同经费(万元)">
                {{ infoview1.contractFunds }}
              </el-descriptions-item>
              <el-descriptions-item label="服务的国民经济行业">
                {{ infoview1.nationalEconomy }}
              </el-descriptions-item>
              <el-descriptions-item label="项目参与人">
                {{ infoview1.projectParticipants }}
              </el-descriptions-item>
              <el-descriptions-item label="协作内容和要求">
                {{ infoview1.contentRequirements }}
              </el-descriptions-item>
              <el-descriptions-item label="预期成果(结题要求)">
                {{ infoview1.expect }}
              </el-descriptions-item>
              <el-descriptions-item label="预期目标和考核目标">
                {{ infoview1.goal }}
              </el-descriptions-item>
              <el-descriptions-item label="知识产权归属及分享">
                {{ infoview1.intellectual }}
              </el-descriptions-item>
              <el-descriptions-item label="工作进度计划">
                {{ infoview1.jobPlan }}
              </el-descriptions-item>
              <el-descriptions-item label="付款计划">
                {{ infoview1.payPlan }}
              </el-descriptions-item>
              <el-descriptions-item label="学科分类">
                {{ infoview1.disciplineClassfi }}
              </el-descriptions-item>
              <el-descriptions-item label="活动类型">
                {{ infoview1.activityType }}
              </el-descriptions-item>
              <el-descriptions-item label="项目来源">
                {{ infoview1.projectSourse }}
              </el-descriptions-item>
              <el-descriptions-item label="组织形式">
                {{ infoview1.organizationForm }}
              </el-descriptions-item>
              <el-descriptions-item label="合作形式">
                {{ infoview1.cooperaForm }}
              </el-descriptions-item>
              <el-descriptions-item label="项目的社会经济目标">
                {{ infoview1.socialEconomy }}
              </el-descriptions-item>
              <el-descriptions-item label="承担二级单位">
                {{ infoview1.secondUnit }}
              </el-descriptions-item>
              <el-descriptions-item label="职称">
                {{ infoview1.title }}
              </el-descriptions-item>
              <el-descriptions-item label="学历">
                {{ infoview1.education }}
              </el-descriptions-item>
              <el-descriptions-item label="项目状态">
                <el-tag :type="infoview1.projectState | statusFilter">{{ infoview1.projectState }}</el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="退回原因">
                {{ infoview1.reason }}
              </el-descriptions-item>
              <el-descriptions-item label="备注">
                {{ infoview1.notes }}
              </el-descriptions-item>
            </el-descriptions>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <div class="el-descriptions__title">量化分数</div>
            </template>
            <div style="margin-bottom: 10px;">
              <span>分数计算规则参考：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/科研项目积分规则可视化.pdf'" target="_blank">科研项目计分规则可视化</el-link>
              <br>
              <span>官方文件：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/湖北师范大学科研工作量化管理办法（修订版）.pdf'" target="_blank">湖北师范大学科研工作量化管理办法（修订版）</el-link>
              <el-switch
                v-model="thesis_source_form.manualScoreMode"
                active-text="手动填分"
                inactive-text="自动计分"
                style="float: right; margin-right: 20px;"
                @change="handleScoreModeChange"
              />
            </div>
            <el-table
              v-loading="sourceListLoading"
              :data="sourceList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column v-if="!thesis_source_form.manualScoreMode" label="一级类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.projectType2 }}
                </template>
              </el-table-column>
              <el-table-column v-if="!thesis_source_form.manualScoreMode" label="到账经费(万元)" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.funds }}
                </template>
              </el-table-column>
              <el-table-column v-if="thesis_source_form.manualScoreMode" align="center" label="算分详情" min-width="200">
                <template slot-scope="scope">
                  {{ scope.row.Note }}
                </template>
              </el-table-column>
              <!-- 通用列 -->
              <el-table-column align="center" label="最终得分" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.finalValue }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="3">
            <template slot="title">
              <div class="el-descriptions__title">成员列表</div>
            </template>
            <el-table
              v-loading="paperAuthorListLoading"
              :data="paperAuthorList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column align="center" label="工号" min-width="100">
                <template slot-scope="scope">
                  {{ (scope.row.authortype === '校内教师' || scope.row.peopleType === '校内教师' || scope.row.authorType === '校内教师' || !scope.row.authorType) && scope.row.userAccount ? scope.row.userAccount : '无' }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.name }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="所属院系" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dept }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="排名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.ranking }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="考核系数" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.assessment }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="个人得分" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.pscore }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="4">
            <template slot="title">
              <div class="el-descriptions__title">到账经费</div>
            </template>
            <el-table
              v-loading="paperDZfundsListLoading"
              :data="paperDZfundsList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" width="55" />
              <el-table-column align="center" label="到账编号" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dzfundsNum }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="到账金额(万元)" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dzfundsAmount }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="经费来源" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.fundsSours }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="到账日期" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dzfundsDate }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="上传时间" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.uploadTime }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="5">
            <template slot="title">
              <div class="el-descriptions__title">支出经费</div>
            </template>
            <el-table
              v-loading="paperZCfundsListLoading"
              :data="paperZCfundsList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" width="55" />
              <el-table-column align="center" label="支出编号" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.zcfundsNum }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="支出金额(万元)" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.zcfundsAmount }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="支出类别" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.zcfundsType }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="支出日期" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.zcfundsDate }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="上传时间" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.uploadTime }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="6">
            <template slot="title">
              <div class="el-descriptions__title">附件信息</div>
            </template>
            <el-table
              v-loading="fileListLoading"
              :data="fileList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" label="序号" width="55" />
              <el-table-column align="left" label="文件名称" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filename }}
                </template>
              </el-table-column>
              <el-table-column align="left" label="文件大小" min-width="150">
                <template slot-scope="scope">
                  <span v-if="scope.row.filesize / 1024 / 1024 < 1">{{ (scope.row.filesize / 1024).toFixed(2) + 'KB' }}</span>
                  <span v-else>{{ (scope.row.filesize / 1024 / 1024).toFixed(2) + 'MB' }}</span>
                </template>
              </el-table-column>
              <el-table-column align="left" label="上传时间" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filedate }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    @click="downloadFile(scope.row)"
                  >
                    下载
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="7">
            <template slot="title">
              <div class="el-descriptions__title">审核记录</div>
            </template>
            <el-table
              v-loading="paperAuditListLoading"
              :data="paperAuditList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" label="序号" width="55" />
              <el-table-column align="center" label="审核员职位" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerRole }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核员姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerName }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="项目状态变化" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.statusChange }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核意见" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditOpinion }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核时间" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerTime }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
        </el-collapse>
        <div slot="footer" class="dialog-footer">
          <el-button @click="infoview_dialog = false">关 闭</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getUserHorizontals, get_thesis_author, get_file, getQulification, get_thesis_DZfunds, get_thesis_ZCfunds, GetHxProjectDTOById, thesis_back_yuanji3, thesis_pass_yuanji3 } from '@/api/horizontal'
import { get_thesis_Audit } from '@/api/audit'
import { getDepts } from '@/api/system'
import { Message } from 'element-ui'
import { mapGetters } from 'vuex'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        草稿: 'info',
        待院审核: '',
        被院级退回: 'danger',
        待校审核: '',
        被校级退回: 'danger',
        审核通过: 'success',
        在研: 'success',
        结题: 'success',
        在研待审核: '',
        结题待审核: '',
        在研退回: 'danger',
        结题退回: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      thesis_source_form: {
        manualScoreMode: false
      },
      search: {
        projectName: '',
        projectSourse: '',
        projectId: '',
        projectCate: '',
        projectUnit: '',
        headName: '',
        projectState: '',
        startTimeStart: '',
        startTimeEnd: '',
        deptName: ''
      },
      thesis_add_dialog: false,
      thesis_info_dialog: false,
      infoview_dialog: false,
      visible1: false,
      visible2: false,
      paperList: null,
      paperListLoading: false,
      paperDZfundsList: [],
      paperDZfundsListLoading: false,
      paperZCfundsList: [],
      paperZCfundsListLoading: false,
      paperAuditList: [],
      paperAuditListLoading: false,
      p1_size: 10,
      p1_total: 0,
      p1_page: 1,
      status1: '审核通过',
      status2: '结题待审核',
      back_post: {
        id: '',
        reason: ''
      },
      paperAuthorList: [],
      paperAuthorListLoading: false,
      infoview1: {
        approvalMaterial: '',
        approvalTime: '',
        approvalYear: '',
        archiveNum: '',
        arrivingFunds: '',
        birthdate: '',
        classifi: '',
        contentRequirements: '',
        contractFunds: '',
        endTime: '',
        entered: '',
        enteredDate: '',
        expect: '',
        financialNum: '',
        goal: '',
        head: '',
        headName: '',
        account: '',
        intellectual: '',
        jobPlan: '',
        notes: '',
        payPlan: '',
        projectCate: '',
        projectId: '',
        projectMembers: '',
        projectName: '',
        projectState: '',
        projectUnit: '',
        reason: '',
        startTime: '',
        status: '',
        title: '',
        tregistrationID: '',
        unit: ''
      },
      activeNames: ['1', '2', '3', '4', '5', '6', '7'],
      fileList: [],
      fileListLoading: false,
      sourceListLoading: false,
      sourceList: [],
      dept_options: [],
      deptLoading: false
    }
  },
  computed: {
    ...mapGetters([
      'uid',
      'roles',
      'name'
    ]),
    MyPaperPost() {
      // 创建一个搜索参数的副本
      const searchParams = { ...this.search }
      // 如果选择了结题相关状态或为空/空格，统一转换为"结题"
      if (['结题待院审核', '结题待校审核', '项目结题', '项目结题退回'].includes(searchParams.projectState) || !searchParams.projectState || searchParams.projectState.trim() === '') {
        searchParams.projectState = '结题'
      }
      // 添加projectFlag参数为2
      searchParams.projectFlag = 2
      return {
        pageNum: this.p1_page,
        pageSize: this.p1_size,
        ...searchParams
      }
    }
  },
  watch: {
    search: {
      handler() {
        this.paperListLoading = true
        clearTimeout(this.searchTimeout)
        this.searchTimeout = setTimeout(() => {
          this.fetchPaperData()
          this.paperListLoading = false
        }, 1500)
      },
      deep: true // 启用深度监视，可监听对象内部属性变化
    }
  },
  created() {
    this.fetchPaperData()
  },
  methods: {
    // 处理切换模式
    handleScoreModeChange(value) {
      this.thesis_source_form.manualScoreMode = value
    },
    fetchPaperData() {
      this.paperListLoading = true
      getUserHorizontals(this.MyPaperPost).then(response => {
        if (response.code === 200) {
          this.paperList = response.data.list
          this.p1_total = response.data.total
          this.paperListLoading = false
          // 为每个项目获取成员数据
          this.paperList.forEach(project => {
            this.fetchProjectMembers(project)
          })
        }
      })
    },
    fetchProjectMembers(project) {
      get_thesis_author(project.tregistrationID).then(response => {
        if (response.code === 200 && response.data && response.data.length > 0) {
          // 过滤掉项目负责人，通过比较姓名
          const filteredMembers = response.data.filter(item => {
            // 检查是否是项目负责人（通过姓名匹配）
            const isResponsible = project.headName && item.name === project.headName
            return !isResponsible
          })
          // 拼接过滤后的成员姓名
          const memberNames = filteredMembers.length > 0
            ? filteredMembers.map(member => member.name).join('、') : '暂无'
          // 使用this.$set确保响应式更新，第一个参数是数组，第二个是索引，第三个是属性名，第四个是值
          const index = this.paperList.indexOf(project)
          if (index !== -1) {
            this.$set(this.paperList[index], 'memberNames', memberNames)
          } else {
            // 如果找不到索引，直接设置（虽然可能不会触发响应式更新，但作为兜底）
            project.memberNames = memberNames
          }
        } else {
          // 同样使用this.$set处理无数据情况
          const index = this.paperList.indexOf(project)
          if (index !== -1) {
            this.$set(this.paperList[index], 'memberNames', '暂无')
          } else {
            project.memberNames = '暂无'
          }
        }
      })
    },
    statusChange() {
      this.fetchPaperData()
    },
    p1_sizechange(newsize) {
      this.p1_size = newsize
      this.p1_page = 1
      this.fetchPaperData()
    },
    p1_currentchange(newpage) {
      this.p1_page = newpage
      this.fetchPaperData()
    },
    filterTag(value, row) {
      return row.status === value
    },
    thesis_back(row) {
      this.$prompt('请输入退回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^.+$/,
        inputErrorMessage: '原因不能为空'
      }).then(({ value }) => {
        this.back_post.id = row.tregistrationID
        this.back_post.reason = value
        thesis_back_yuanji3(this.back_post).then(response => {
          if (response.code === 200) {
            Message.success('退回成功')
            this.fetchPaperData()
          }
        })
      }).catch(() => {
        Message.info('取消退回')
      })
    },
    thesis_pass(index, row) {
      this.$refs[`popoverpass-${index}`].doClose()
      thesis_pass_yuanji3(row.tregistrationID).then(response => {
        if (response.code === 200) {
          Message.success('通过成功')
          this.fetchPaperData()
        }
      })
    },
    fetchOneData() {
      GetHxProjectDTOById(this.infoview1.tregistrationID).then(response => {
        if (response.code === 200) {
          this.infoview1 = response.data
          // 字段映射
          this.infoview1.organization = response.data.deptName
          this.infoview1.entered = response.data.enteredName
          // 项目详情加载完成后，获取并过滤成员列表
          this.paperAuthorListLoading = true
          get_thesis_author(this.infoview1.tregistrationID).then(authorResponse => {
            if (authorResponse.code === 200) {
              // 显示所有作者，包括项目负责人
              this.paperAuthorList = authorResponse.data
              this.paperAuthorListLoading = false
            }
          })
        }
      })
    },
    open_infoview_dialog(row) {
      this.infoview_dialog = true
      this.infoview1 = JSON.parse(JSON.stringify(row))
      this.fetchOneData()
      this.fileListLoading = true
      get_file(row.tregistrationID).then(response => {
        if (response.code === 200) {
          this.fileList = response.data
          this.fileListLoading = false
        }
      })
      this.sourceListLoading = true
      getQulification(row.tregistrationID).then(response => {
        if (response.code === 200) {
          this.sourceList = response.data
          this.sourceListLoading = false
          // 检查是否已手动填分，如果是则自动切换到手动填分模式
          if (response.data.length > 0 && response.data[0].manualScoreMode === 'true') {
            this.thesis_source_form.manualScoreMode = true
          } else {
            this.thesis_source_form.manualScoreMode = false
          }
        }
      })
      this.paperDZfundsListLoading = true
      get_thesis_DZfunds(row.tregistrationID).then(response => {
        if (response.code === 200) {
          this.paperDZfundsList = response.data
          this.paperDZfundsListLoading = false
        }
      })
      this.paperZCfundsListLoading = true
      get_thesis_ZCfunds(row.tregistrationID).then(response => {
        if (response.code === 200) {
          this.paperZCfundsList = response.data
          this.paperZCfundsListLoading = false
        }
      })
      this.paperAuditListLoading = true
      get_thesis_Audit(row.tregistrationID).then(response => {
        if (response.code === 200) {
          this.paperAuditList = response.data
          this.paperAuditListLoading = false
        }
      })
    },
    downloadFile(row) {
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      // 确保文件路径正确拼接，处理fileupload文件夹的路径
      let fileUrl = row.fileurl
      if (!fileUrl.startsWith('https')) {
        // 如果不是完整URL，则拼接FILE_PATH
        if (fileUrl.startsWith('/')) {
          fileUrl = this.$FILE_PATH + fileUrl
        } else {
          fileUrl = this.$FILE_PATH + '/' + fileUrl
        }
      }
      a.href = fileUrl
      a.target = '_blank'
      a.dispatchEvent(event)
    },
    fetchDeptData() {
      if (this.dept_options.length === 0) {
        this.deptLoading = true
        getDepts().then(response => {
          if (response.code === 200) {
            this.dept_options = response.data
            this.deptLoading = false
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">
.el-form{
  margin-left: 40px;
  .el-input,.el-select{
    width: 300px;
  }
}
.el-tag + .el-tag {
  margin: 10px 10px;
}
.margin-top {
  margin-top: 50px;
}
@media screen and (max-width:600px) {
  .el-dialog{
    width: 100% !important;
  }
  .el-form{
    margin-left: 25px;
  }
}
</style>
